/**
 * @file 
 */
#include "StdAfx.h"
#include "NTEngine/Graphics/Manager.h"
#include "NTEngine/Math/Matrix3x4.h"
#include "NTEngine/Math/Matrix4x4.h"
#include "NTEngine/Math/Vector3.h"
#include "NTEngine/Math/Vector4.h"
#include "NTEngine/Scene/ShadowMapEffect.h"
#include "NTEngine/Base/ReferenceType.h"

#include "Graphics/src/Shader/ShadowMapVs1/ShadowMapVsP1.h"
#include "Graphics/src/Shader/ShadowMapVs2/ShadowMapVsP2.h"
#include "Graphics/src/Shader/ShadowMapPs1/ShadowMapPsP1.h"
#include "Graphics/src/Shader/ShadowMapPs2/ShadowMapPsP2.h"

namespace NTEngine {
using namespace Math;
using namespace Graphics;
namespace Scene {

class ShadowMapEffect::Impl : public ReferenceType {
public:
	Impl() {
		Graphics::Manager gm;
		gm.loadVertexShader( (char*)g_vs20_ShadowMapVsP1, &m_Pass[ 0 ].vs );
		gm.loadVertexShader( (char*)g_vs20_ShadowMapVsP2, &m_Pass[ 1 ].vs );
		gm.loadPixelShader( (char*)g_ps20_ShadowMapPsP1, &m_Pass[ 0 ].ps );
		gm.loadPixelShader( (char*)g_ps20_ShadowMapPsP2, &m_Pass[ 1 ].ps );
	}
	~Impl() {
		Graphics::Manager gm;
		gm.unloadVertexShader( &m_Pass[ 0 ].vs );
		gm.unloadVertexShader( &m_Pass[ 1 ].vs );
		gm.unloadPixelShader( &m_Pass[ 0 ].ps );
		gm.unloadPixelShader( &m_Pass[ 1 ].ps );
	}

	void apply( int pass ) {
		ASSERT( 0 >= pass && 2 < pass );
		Graphics::Manager gm;
		switch ( pass ) {
		case 0:
			gm.commitShader( &m_Pass[ pass ].vs, &m_Pass[ pass ].ps );
			break;
		case 1:
			gm.commitShader( &m_Pass[ pass ].vs, &m_Pass[ pass ].ps );
			break;
		}
	}

	struct Pass {
		int vs;
		int ps;
	};
	Pass m_Pass[ 2 ]; // 2 pass
};

ShadowMapEffect ShadowMapEffect::create() {
	ShadowMapEffect ret;
	ret.m_Impl = NEW Impl();
	return ret;
}

void ShadowMapEffect::apply( int pass ) {
	ASSERT( m_Impl && "Empty Object" );
	m_Impl->apply( pass );
}

#define TYPE ShadowMapEffect
#include "NTEngine/Base/Impl/ReferenceTypeTemplate.h"

} // namespace Scene
} // namespace NTEngine
// EOF